<?php 

// 用户控制器

class UserController extends Controller
{	
	private $model =null;
	public function __construct()
	{
		parent::__construct();
		$this->model =new Model('user');
	}

	public function Index()
	{
		$data =$this->model->order('id desc')->select();
		$this->assign('title','用户列表');

		$this->assign('list',$data);
		$this->display('User/index.html');


	}
	//显示表单
	public function add()
	{
		$this->assign('title','添加用户');
		$this->display('User/add.html');
	}
	//执行添加
	public function insert()
	{
		if($this->model->insert()>0){
			$this->redirect('添加成功','./index.php?c=user&a=index');
		}else{
			$this->redirect('添加失败');

		}
	}
	public function del()
	{
		if($this->model->delete($_GET['id'])){
			$this->redirect('删除成功','./index.php?c=user&a=index');
		}else{
			$this->redirect('删除失败');

		}
	}


	// 显示编辑表单
	public function edit()
	{	$data =$this->model->find($_GET['id']);
		$this->assign('title','添加用户');
		$this->assign('data',$data);
		$this->display('User/edit.html');
	}
	//执行编辑
	public function update()
	{
		if($this->model->update()>0){
			$this->redirect('编辑成功','./index.php?c=user&a=index');
		}else{
			$this->redirect('编辑失败');

		}
	}
}